<template>
  <el-form :inline="true" :model="queryData">
    <el-form-item>
      <el-select v-model="value" class="mr-1" placeholder="请选择试题类型">
        <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
        >
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-input placeholder="内容"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary">查询</el-button>
    </el-form-item>
    <el-form-item>
      <el-button>重置</el-button>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="$router.push('/train_manage/add_topic')">新增</el-button>
    </el-form-item>

  </el-form>
  <!--  表格-->
  <AutoTable ref="proTable" :request="getListData" class="mb-2" :columns="columns">
    <template #quType="{row}">
      <div>{{ topicType[row.quType] }}</div>
    </template>
    <template #handle="{row}">
      <el-button size="small" type="primary">修改</el-button>
      <el-button size="small" type="danger" @click="deleteTopic(row.id)">删除</el-button>
    </template>
  </AutoTable>
</template>

<script>
export default {
  name: "TopicManage"
}
</script>
<script setup>
import AutoTable from '@/components/AutoTable'
import {ref, reactive, getCurrentInstance, onMounted} from "vue";
import {topicType} from "@/utils/enum";
import api from "@/http_config/api";

const proTable = ref(null);

// 刷新
const refresh = () => {
  proTable.value.refresh();
};
const options = [
  {
    label: '单选',
    value: 1,
  },
  {
    label: '多选',
    value: 2,
  },
  {
    label: '判断',
    value: 3,
  }
]
const queryData = {}
const columns = [
  {
    label: '题目名称',
    prop: 'content'
  },
  {
    label: '题型',
    prop: 'quType',
    tdSlot: 'quType',
    width: 120,
  },
  {
    label: '试题类型',
    prop: 'teType',
    width: 120,
  },
  {
    label: '操作',
    tdSlot: 'handle',
  },
]

const proxy = getCurrentInstance().proxy
//表单接口-查询
const getListData = async (params) => {
  const data = await proxy.$http.get(api.trainManage.topicManage.list, {params})
  // 必须要返回一个对象，包含data数组和total总数
  return {
    data: data.data,
    total: +data.total,
  };
}
//删除
const deleteTopic = (ids) => {
  proxy.$http.delete(api.trainManage.topicManage.delete, {
    params: {
      ids
    }
  }).then((res) => {
    refresh()
  })

}


</script>
<style scoped>

</style>
